from flask import Flask, Blueprint

from modules.task.interval import start_check
from modules.utils.errorhandler import handle_exception
from modules.view.views import view_namespace
from flask_cors import CORS
from flask_restx import Api

app = Flask(__name__)
app.register_error_handler(Exception, handle_exception)
app.config['RESTX_MASK_SWAGGER'] = False
cors = CORS()
app = Flask(__name__)


# 注册蓝图
def register_blueprints():
    blueprint = Blueprint('api', __name__, url_prefix='/v1')
    api = Api(blueprint,
              version="1.0",
              title="热搜据合app",
              description="热搜据合app,多个搜索平台热搜据合",
              )
    api.add_namespace(view_namespace)
    """Register Flask blueprints."""
    origins = app.config.get('CORS_ORIGIN_WHITELIST', '*')
    cors.init_app(blueprint, origins=origins)  # 处理跨域
    app.register_blueprint(blueprint)


register_blueprints()
# 开启任务
start_check()
if __name__ == '__main__':
    app.run(threaded=True, host='0.0.0.0', port=5000, debug=True)
